package com.it.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.it.Mapper.SalesOrderMapper2;
import com.it.service.SalesOrderService2;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.it.pojo.SalesOrder;
import org.springframework.stereotype.Service;
@Service
public class SalesOrderServiceImpl2 extends ServiceImpl<SalesOrderMapper2, SalesOrder>implements SalesOrderService2 {
    @Override
    public Page<SalesOrder> getSalesOrderList(String search, Integer page, Integer pageSize) {
        Page<SalesOrder> pageParam = new Page<>(page-1, pageSize);
        LambdaQueryWrapper<SalesOrder> queryWrapper = new LambdaQueryWrapper<>();

        if (StringUtils.isNotBlank(search)) {
            queryWrapper.like(SalesOrder::getSalesOrderId, search)  // 订单编号
                    .or()
                    .like(SalesOrder::getName, search)  // 客户名称
                    .or()
                    .like(SalesOrder::getStatus, search);      // 订单状态
        }
        return this.page(pageParam, queryWrapper);
    }

    @Override
    public boolean createSalesOrder(SalesOrder salesOrder) {
        return this.save(salesOrder);
    }

    @Override
    public boolean updateSalesOrder(Integer id, SalesOrder salesOrder) {
        salesOrder.setSalesOrderId(id);
        return this.updateById(salesOrder);
    }

    @Override
    public boolean deleteSalesOrder(Integer id) {
        return this.removeById(id);
    }

}
